﻿@using SplendidCRM
@using SplendidCRM.Ext
@using SplendidCRM.Ext.Helpers
@using SplendidCRM.Ext.Models
@model CaseDetailsViewModel

@{
    var formId = Guid.NewGuid();
}

<form id="@formId" class="form" autocomplete="off" data-bind="noSubmit: true">
    <div class="form-header">Case Info</div>
    <div class="form-section">
        @Html.Field(FieldType.Dropdown, "Priority", "options: { source: PriorityList, text: 'x.value', value: 'x.key' }, value: Priority")
        @Html.Field(FieldType.Dropdown, "Status", "options: { source: StatusList, text: 'x.value', value: 'x.key' }, value: Status")
        @Html.Field(FieldType.Text, new { fieldLabel = "Subject", containerClass = "solid-border" }, "value: Subject")
        @Html.Field(FieldType.Span, "Assigned to", "text: AssignedUserName")
        @Html.Field(FieldType.TextArea, new { fieldClass = "h2x", fieldLabel = "Resolution", containerClass = "solid-border" }, "value: Resolution")
        @Html.Field(FieldType.Span, "Account name", "text: AccountName")
        @Html.Field(FieldType.TextArea, new { fieldClass = "h2x", fieldLabel = "Description", containerClass = "solid-border" }, "value: Description")
        <div class="clear"></div>
    </div>

    <div class="form-command">
        <input type="submit" class="form-button" value="Save" href="@Url.Action(Model.ConvertToCase ? "ConvertToCase" : "SaveCaseDetails")" data-bind="send: save()" />
    </div>
    <div class="clear"></div>
</form>

<script type="text/javascript">
    $(function () {
        Globalize.culture('vi');
        var model = @Html.Raw(Model.Json(true)) ;
        model.save = function() {
            return {
                stringify: true,
                updated: function(data) {
                    @if(Model.ConvertToCase)
                    {
                        @:alert('New case created');
                    }
                    else
                    {
                        @:alert('Case saved');
                    }
                    closeLightBox(data);
                },
                preProcess: function(data) {
                    delete data.PriorityList;
                    delete data.StatusList;
                    return data;
                }
            };
        };
        linq.model(model, '#@formId');
    });
</script>